package com.study.sbsummary.controller;

import com.study.sbsummary.model.Order;
import com.study.sbsummary.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    OrderService orderService;

    @GetMapping("/listAll")
    public List<Order> getAllOrder() {
        List<Order> orders = orderService.listOrder();
        return orders;
    }

    @GetMapping("/get")
    public Order getById(@RequestParam("id") Long id) {
        Order order = orderService.selectOrderById(id);
        return order;
    }

    @PostMapping("/add")
    public Boolean insert(Order order) {
        int i = orderService.addOrder(order);
        return i==1;
    }

    @PostMapping("/delById")
    public Boolean delete(@RequestBody Order order) {
        int i = orderService.updateOrder(order);
        return i==1;
    }
}
